package net.kem.android.positioner.custom;

import android.content.Context;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import net.kem.android.positioner.Macro;
import net.kem.android.positioner.PositionerService;

public class MacroMessageButton extends ServerMessageElement {
	protected Button button;

	public MacroMessageButton(PositionerService.LocalBinder binder, Context context, int imageResouceId, Macro macro) {
		this(binder, context, (AttributeSet)null, imageResouceId, macro);
	}
	public MacroMessageButton(PositionerService.LocalBinder binder, Context context, AttributeSet attrs, int imageResouceId, Macro macro) {
		super(binder, context, new Point(300, 300), attrs, macro);
		
		image = new ImageView(context);
		image.setImageResource(imageResouceId);
		image.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions

		button = new Button(context, attrs);
		button.setText("Run macro");
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				sendServerMessage();
			}
		});
		addView(button);
	}
	
	protected void sendServerMessage() {
		binder.sendMacro((Macro)namable);
}
}